home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / eXec / Krotkie opisy / Programy / XADMaster / xad_Wrapster.lha / Wrapster.c < prev    next >
C/C++ Source or Header  |  2000-12-03  |  6KB  |  195 lines

  1. /* Wrapster file archiver client for XAD.
  2.  * Copyright (C) 2000 Stuart Caie <kyzer@4u.net>
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  * 
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  * 
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18.  
  19. /* Wrapster is a way of using the Napster MP3 sharing system to not only
  20.  * share MP3s, but any files you like.
  21.  * See http://members.fortunecity.com/wrapster/ for more information.
  22.  *
  23.  * The CRC32 feature of Wrapster is ignored completely, for two reasons:
  24.  * - the Wrapster authors haven't told anybody what the CRC calculation is
  25.  * - because of this, other wrapper authors have used different CRCs!!!!
  26.  * Therefore, there's no real point checking.
  27.  */
  28.  
  29. /* From the Wrapster 2.0 .HLP file:
  30.  * Wrapster File Format for v1.0 and v2.0
  31.  *
  32.  * Ok... here is the official specification for the layout of a Wrapster
  33.  * file. This section is intended for programmers and anyone who might be
  34.  * curious about how this whole thing works. The reasons for including this
  35.  * specification is to encourage other programmers to write their own
  36.  * Wrapster clones for other Operating Systems, or to extend the features
  37.  * of the Windows version of Wrapster itself. If you extend the features of
  38.  * Wrapster, use some of the unused bytes so that your client can easily
  39.  * identify those files which it creates.
  40.  * 
  41.  * A Wrapster file will have the following format on disk:
  42.  * 
  43.  * Header
  44.  *   FrameHeader           4 bytes         0xFF, 0xFB, 0x18, 0x0C
  45.  *   Reserved (Unused)     6 bytes
  46.  *   Signature             10 bytes        "wrapster"#0#0
  47.  *   Version               8 bytes         "2.0"#0#0#0#0#0
  48.  *   FileCount             4 bytes
  49.  * 
  50.  * Wrapster File Entry
  51.  * 
  52.  * Immediately following the header of the file you will find FileCount
  53.  * entries each containing the following data
  54.  * 
  55.  *   OriginalFileName      256 bytes
  56.  *   Reserved (Unused)     32 bytes
  57.  *   CRC32                 4 bytes
  58.  *   Size                  4 bytes
  59.  *   FileData              Size bytes
  60.  * 
  61.  * Padding
  62.  * 
  63.  * After all file entries in the Wrapster file you will encounter padding
  64.  * that helps to assure that the files contained within the archive remain
  65.  * intact. This was done as a precaution since many downloads across
  66.  * Napster tend to get the last few bytes cut off.
  67.  * 
  68.  * ID3 Tag
  69.  * The last 128 bytes of the padding contain an MP3 identification tag that
  70.  * will show up in the play-list of programs like Winamp as an ID3 tag. You
  71.  * may put any values in here that you like. See the MP3 specification for
  72.  * more information.
  73.  */
  74.  
  75. #include "SDI_compiler.h"
  76. #include "ConvertE.c"
  77. #include <exec/types.h>
  78. #include <exec/memory.h>
  79. #include <string.h>
  80. #include <libraries/xadmaster.h>
  81. #include <proto/xadmaster.h>
  82.  
  83.  
  84. #ifndef XADMASTERFILE
  85. #define Wrap_Client        FirstClient
  86. #define NEXTCLIENT        0
  87. const UBYTE version[] = "$VER: Wrapster 1.1 (05.08.2000)";
  88. #endif
  89. #define WRAP_VERSION        1
  90. #define WRAP_REVISION        1
  91.  
  92. #define XADBASE  REG(a6, struct xadMasterBase *xadMasterBase)
  93.  
  94.  
  95. #define head_magic      (0x00)
  96. #define head_reserved   (0x04)
  97. #define head_signature  (0x0a)
  98. #define head_version    (0x14)
  99. #define head_filecount  (0x1c)
  100. #define head_SIZEOF     (0x20)
  101.  
  102. #define file_name       (0x000)
  103. #define file_reserved   (0x100)
  104. #define file_crc32      (0x120)
  105. #define file_size       (0x124)
  106. #define file_SIZEOF     (0x128)
  107.  
  108. ASM(BOOL) Wrap_RecogData(REG(d0, ULONG size), REG(a0, STRPTR d), XADBASE) {
  109.   return (BOOL) (d[0]==0xFF && d[1]==0xFB && d[2]==0x18 && d[3]==0x0C
  110.                  && memcmp(d+10, "wrapster\0\0", 10) == 0) ? 1 : 0;
  111. }
  112.  
  113. ASM(LONG) Wrap_GetInfo(REG(a0, struct xadArchiveInfo *ai), XADBASE) {
  114.   ULONG filenum = 1, numfiles;
  115.   struct xadFileInfo *link = NULL,  *fi;
  116.   LONG err = XADERR_OK;
  117.   UBYTE buffer[296], *p;
  118.  
  119.   struct TagItem filetags[]  = {
  120.     { XAD_OBJNAMESIZE, 257 },
  121.     { TAG_DONE, 0 }
  122.   };
  123.  
  124.   struct TagItem datetags[] = {
  125.     { XAD_DATECURRENTTIME, 1 },
  126.     { XAD_GETDATEXADDATE,  0 },
  127.     { TAG_DONE, 0 }
  128.   };
  129.  
  130.   /* read the file header */
  131.   if ((err = xadHookAccess(XADAC_READ, head_SIZEOF, buffer, ai))) return err;
  132.  
  133.   /* check the version - is it "1.0" or "2.0" ? */
  134.   if (buffer[head_version] != '1' && buffer[head_version] != '2') {
  135.     return XADERR_DATAFORMAT;
  136.   }
  137.  
  138.   /* get the number of files in this archive */
  139.   numfiles = EndGetI32(buffer+head_filecount);
  140.  
  141.   while (numfiles--) {
  142.     /* read the file header */
  143.     if ((err = xadHookAccess(XADAC_READ, file_SIZEOF, buffer, ai))) break;
  144.  
  145.     fi = (struct xadFileInfo *) xadAllocObjectA(XADOBJ_FILEINFO, filetags);
  146.     if (!fi) { err = XADERR_NOMEMORY; break; }
  147.  
  148.     fi->xfi_EntryNumber = filenum++;
  149.     fi->xfi_Size        = EndGetI32(buffer+file_size);
  150.     fi->xfi_Flags       = XADFIF_SEEKDATAPOS;
  151.     fi->xfi_DataPos     = ai->xai_InPos;
  152.  
  153.     /* copy filename */
  154.     xadCopyMem(buffer+file_name, fi->xfi_FileName, 256);
  155.     fi->xfi_FileName[256] = '\0';
  156.  
  157.     fi->xfi_CrunchSize = fi->xfi_Size;
  158.  
  159.     /* fix MS-DOS filenames */
  160.     for (p = fi->xfi_FileName; *p; p++) if (*p == '\\') *p = '/';
  161.  
  162.     /* fill in today's date */
  163.     datetags[1].ti_Data = (ULONG) &fi->xfi_Date;
  164.     xadConvertDatesA(datetags);
  165.  
  166.     if (link) link->xfi_Next = fi; else ai->xai_FileInfo = fi;
  167.     link = fi;
  168.  
  169.     if ((err = xadHookAccess(XADAC_INPUTSEEK, fi->xfi_Size, NULL, ai))) break;
  170.   }
  171.  
  172.   if (err) {
  173.     if (!ai->xai_FileInfo) return err;
  174.     ai->xai_Flags |= XADAIF_FILECORRUPT;
  175.     ai->xai_LastError = err;
  176.   }
  177.   return XADERR_OK;
  178. }
  179.  
  180. ASM(LONG) Wrap_UnArchive(REG(a0, struct xadArchiveInfo *ai), XADBASE) {
  181.   return xadHookAccess(XADAC_COPY, ai->xai_CurFile->xfi_Size, NULL, ai);
  182. }
  183.  
  184. const struct xadClient Wrap_Client = {
  185.   NEXTCLIENT, XADCLIENT_VERSION, 6, WRAP_VERSION, WRAP_REVISION,
  186.   32, XADCF_FILEARCHIVER | XADCF_FREEFILEINFO,
  187.   0, "Wrapster",
  188.  
  189.   /* client functions */
  190.   (BOOL (*)()) Wrap_RecogData,
  191.   (LONG (*)()) Wrap_GetInfo,
  192.   (LONG (*)()) Wrap_UnArchive,
  193.   NULL
  194. };
  195.